/**
 * Copyright (C) 2012 Oleg Anastassov <o.anastasov@gmail.com>
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kz.kstu.ent.business.entity;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Date: 28.08.12
 * Time: 21:04
 *
 * @author Oleg Anastassov
 */
@Entity
@Table(name = "STUDENT")
@NamedQueries({
        @NamedQuery(name = QueryNames.STUDENT_FIND_ALL, query =
                "SELECT S " +
                        "FROM Student S "
        ),
        @NamedQuery(name = QueryNames.STUDENT_FIND_BY_ID, query =
                "SELECT S " +
                        "FROM Student S " +
                        "WHERE S.id = (:id) "
        ),
        @NamedQuery(name = QueryNames.STUDENT_FIND_BY_SURNAME, query =
                "SELECT S " +
                        "FROM Student S " +
                        "WHERE UPPER(S.surname) LIKE :surname || '%' "
        )
})
public class Student implements Identifiable {

    private Long id;

    private String surname;

    private String name;

    private String patronymic;

    private Date birthday;

    private Grade grade;

    private Boolean isAltynBelgi;

    private List<ResultSheet> resultSheetList;

    public Student() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "SURNAME", nullable = false)
    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    @Column(name = "NAME", nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "PATRONYMIC", nullable = false)
    public String getPatronymic() {
        return patronymic;
    }

    public void setPatronymic(String patronymic) {
        this.patronymic = patronymic;
    }

    @Column(name = "BIRTHDAY", nullable = false)
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @ManyToOne
    @JoinColumn(name = "GRADE_ID", referencedColumnName = "ID", nullable = false)
    public Grade getGrade() {
        return grade;
    }

    public void setGrade(Grade grade) {
        this.grade = grade;
    }

    @Column(name = "IS_ALTYN_BELGI", nullable = false)
    public Boolean getAltynBelgi() {
        return isAltynBelgi;
    }

    public void setAltynBelgi(Boolean altynBelgi) {
        isAltynBelgi = altynBelgi;
    }

    @OneToMany(mappedBy = "student", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public List<ResultSheet> getResultSheetList() {
        return resultSheetList;
    }

    public void setResultSheetList(List<ResultSheet> resultSheetList) {
        this.resultSheetList = resultSheetList;
    }
}
